package com.qf.topic;

import com.qf.util.RabbitMQUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

/**
 * @author zjw
 * @description
 * @date 2021/11/8 17:26
 */
public class Publisher {

    @Test
    public void test() throws Exception {
        //1. 获取连接对象
        Connection connection = RabbitMQUtil.getConnection();

        //2. 构建Channel
        Channel channel = connection.openChannel().get();

        //3. 构建交换机
        channel.exchangeDeclare("topic_exchange", BuiltinExchangeType.TOPIC);
        channel.queueBind("topic_queue1","topic_exchange","*.orange.*");
        channel.queueBind("topic_queue2","topic_exchange","*.*.rabbit");
        channel.queueBind("topic_queue2","topic_exchange","lazy.#");

        //4. 发送
        channel.basicPublish("topic_exchange","big.orange.rabbit",null,"大橙兔！".getBytes());
        channel.basicPublish("topic_exchange","big.white.rabbit",null,"大白兔！".getBytes());
        channel.basicPublish("topic_exchange","lazy.orange.dog",null,"懒橘狗！".getBytes());

        //5. 释放资源
        channel.close();
        connection.close();
    }

}
